import {findCmdList, createCmd, deleteCmd, updateCmd} from "../api/cmdApi";
import {createDefparam, findDefparamList, updateDefparam, deleteDefparam} from "../api/defaultParamsApi";
const GraphQLJSON = require("graphql-type-json");

const resolveFunctions = {
  JSON: GraphQLJSON,
  Query: {
      /**
       * 查询方法库
       *
       * @param {any} _
       * @param {any} {description}
       * @returns
       */
      async cmd(_, params) {
          let cmdList = await findCmdList(params);
          return cmdList;
      },
      /**
       * 查询方法库
       *
       * @param {any} _
       * @param {any} {description}
       * @returns
       */
      async defaultParams(_, params) {
        let defaultParams = await findDefparamList(params);
        return defaultParams
    },

  },
  Mutation: {
      /**
       * 创建CMD
       */
      async createCmd(_, params) {
          await createCmd(params);
          const res = await findCmdList();
          return res;
      },
      /**
       * 更新cmd
       */
      async updateCmd(_, {id, cmd}) {
        return await updateCmd({_id: id}, cmd);
      },
      /**
       * 删除CMD
       */
      async deleteCmd(_, params) {
        await deleteCmd(params.id);
        return await findCmdList();
      },
      /**
       * 创建参数
       */
      async createDefparam(_, params) {
        return await createDefparam(params);
      },
      /**
       * 更新参数
       */
      async updateDefparam(_, {_id, params}) {
        return await updateDefparam({_id:_id}, params);
      },
      /**
       * 删除参数
       */
      async deleteParams(_, {_id}) {
        return await deleteDefparam(_id)
      }
  }
};

export default resolveFunctions;
